package day_6_29;

import java.util.ArrayList;
import java.util.List;

public class Main2 {
    /**
     * 71. 简化路径
     * https://leetcode.cn/problems/simplify-path/description/
     */
    public String simplifyPath(String path) {
        List<String> list = new ArrayList<>();
        String[] paths = path.split("/");
        for(String s : paths) {
            if(s.isEmpty() || s.equals(".")) {
                continue;
            }
            if(!s.equals("..")) {
                list.add(s);
            }else {
                if(!list.isEmpty()) {
                    list.remove(list.size() - 1);
                }
            }
        }

        return "/" + String.join("/",list);
    }
}
